package com.pingan.util;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

public class HttpContentUntil {
    public static void main(String[] args) throws IOException {
        String url = "https://search.jd.com/Search?keyword=java";
        Document document = Jsoup.parse(new URL(url), 30000);
        String text = document.html();

        Element goodsList = document.getElementById("J_goodsList");

        Elements list = goodsList.getElementsByTag("li");
        int i = 0;
        for (Element element : list) {
            i++;
            String price = element.getElementsByClass("p-price").eq(0).text();
            String[] priceSplit = price.split("￥");
            String name = element.getElementsByClass("p-name").eq(0).text();
            price = priceSplit[1];
            System.out.println(price);
            System.out.println(name);
        }
        System.out.println(i);
    }
}
